﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.OleDb;

public partial class DodadiVino : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
         if (Page.IsValid)
        {
            string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
            OleDbConnection conn = new OleDbConnection(conString);

            conn.Open();

            string imeVin = ddlVinarii.SelectedItem.ToString();
            string select = "select IDVinarija from Vinarija where Ime = ?";
            OleDbCommand cmd1 = new OleDbCommand(select, conn);
            cmd1.Parameters.AddWithValue("?", imeVin);
            OleDbDataReader read = cmd1.ExecuteReader();
            read.Read();
            int idVinarija = Convert.ToInt32(read["IDVinarija"].ToString());

            string insert = "insert into Vina (IDVinarija, ImeVino, CenaZaLitar, SortaNaGrozje, Sorta, Alkohol)values (?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(insert, conn);
        

            string ime = imeV.Text;
            string sortagrozje = sortaG.Text;
            string sortavino = sortaV.Text;
            string cenalitar = cena.Text;
            string a = alkohol.Text;
           
                

            cmd.Parameters.AddWithValue("?", idVinarija);
            cmd.Parameters.AddWithValue("?", ime);
            cmd.Parameters.AddWithValue("?", Convert.ToInt32(cenalitar));
            cmd.Parameters.AddWithValue("?", sortagrozje);
            cmd.Parameters.AddWithValue("?", sortavino);
            cmd.Parameters.AddWithValue("?", Convert.ToDouble(a));
            cmd.ExecuteNonQuery();

            conn.Close();
            Response.Redirect("~/Administrator.aspx");

        }
    }
 }

